package com.xxx.corejava.day1106;

import java.util.Scanner;

public class Test5 {

    public static void main(String[] args) {

        Scanner sc=new Scanner(System.in);

        String[][] rooms=new String[10][12];

        for (int i = 0; i < rooms.length; i++) {
            for (int j = 0; j < rooms[i].length; j++) {
                rooms[i][j]="EMPTY";
            }
        }

        String cmd=null;

        do{

            System.out.println("输入命令:");
            cmd=sc.next();

            if("search".equals(cmd)){
                search(rooms);
            }

            if("in".equals(cmd)){
                String roomNo=sc.next();
                String name=sc.next();
                in(roomNo,name,rooms);
            }

            if("out".equals(cmd)){
                String roomNo=sc.next();
                out(roomNo,rooms);
            }
 

        }while (!"quit".equals(cmd));

        System.out.println("再见");

    }

    public static void out(String roomNo,String[][] rooms){
        int roomNoInt=Integer.parseInt(roomNo);
        int i=roomNoInt/100-1;
        int j=roomNoInt%100-1;

        if("EMPTY".equals(rooms[i][j])){
            System.out.println("房间没有客人，请重新输入");
            return;
        }

        rooms[i][j]="EMPTY";
        System.out.println(roomNo+"退房成功");
    }

    public static void in(String roomNo,String name,String[][] rooms){
        int roomNoInt=Integer.parseInt(roomNo);
        int i=roomNoInt/100-1;
        int j=roomNoInt%100-1;

        if(!"EMPTY".equals(rooms[i][j])){
            System.out.println("房间已有客人，请重新输入");
            return;
        }


        rooms[i][j]=name;
        System.out.println(name+"成功入住"+roomNo+"房间");
    }

    public static void search(String[][] rooms){
        for (int i = 0; i < rooms.length; i++) {


            for (int j = 0; j < rooms[i].length; j++) {
                int roomNoInt=(i+1)*100+(j+1);
                System.out.print(String.format("%04d",roomNoInt)+"\t");
            }
            System.out.println();
            for (int j = 0; j < rooms[i].length; j++) {
                System.out.print(String.format("%4s",rooms[i][j])+"\t");
            }
            System.out.println();
            System.out.println();
            
        }
    }

}
